<!doctype html>
<html lang="en">
<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">

    <title>Leetcode</title>
</head>
<body>


<div class="container-fluid">
    <p class="text-danger">红色标记表示没有解决的问题。</p>
    <p>recursive是程序调用本身，传递不同的参数，iterative是使用for循环的方式。</p>
</div>

<ol>
    <li class="text-primary">Two Sum</li>
    <p>Given an array of integers, return indices of the two numbers such that they add up to a specific target.<br>
        You may assume that each input would have exactly one solution, and you may not use the same element twice.</p>
    <pre><code>vector&lt;int&gt; twoSum(vector&lt;int&gt;& nums, int target);</code></pre>
    <p>for循环遍历vector, 如果map中存在对应的值，则返回该value值和当前遍历的下标值，如果不存在就把值和下标存入map中。</p>


    <li class="text-secondary">Add Two Numbers</li>
    <p>You are given two non-empty linked lists representing two non-negative integers. The digits are stored in
        reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list.</p>
    <pre><code>ListNode* addTwoNumbers(ListNode* l1, ListNode* l2);</code></pre>
    <p>保持进位，两个链表相加，使用其中一个链表进行存储。</p>

    <li class="text-success">Longest Substring Without Repeating Characters</li>
    <p>Given a string, find the length of the longest substring without repeating characters.</p>
    <pre><code>int lengthOfLongestSubstring(string s);</code></pre>
    <p>动态规划(Dynamic programming)，通过数组保存字符和下标值，缓存计算的中间值，不断递进，通过比较返回最终结果。</p>

    <li class="text-danger">Median of Two Sorted Arrays</li>
    <p>There are two sorted arrays nums1 and nums2 of size m and n respectively. <br>
        Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).</p>
    <pre><code>double findMedianSortedArrays(vector&lt;int&gt;& nums1, vector&lt;int&gt;& nums2);</code></pre>
    <p>需要考虑时间复杂度。</p>

    <li class="text-warning">Longest Palindromic Substring</li>
    <p>Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.</p>
    <pre><code>string longestPalindrome(string s);</code></pre>
    <p>依次向左右拓展，比较是否相等，注意处理相同字符的情况。</p>

    <li class="text-info">ZigZag Conversion</li>
    <p>The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want
        to display this pattern in a fixed font for better legibility)</p>
    <pre><code>string convert(string s, int numRows);</code></pre>
    <p>每一行都会有有两个周期交替出现，每行都会走完一次字符串长度。</p>

    <li class="text-dark">Reverse Integer</li>
    <p>Given a 32-bit signed integer, reverse digits of an integer.</p>
    <pre><code>int reverse(int x);</code></pre>
    <p>注意题目的限制，不要使用长整形。</p>

    <li class="text-success">String to Integer (atoi)</li>
    <p>Implement atoi which converts a string to an integer.</p>
    <pre><code>int myAtoi(string str);</code></pre>
    <p>更像是考察if-else语句。</p>

    <li class="text-info">Palindrome Number</li>
    <p>Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward.</p>
    <pre><code>bool isPalindrome(int x);</code></pre>
    <p>将数值的一半倒置判断是否相等。</p>

    <li class="text-danger">Regular Expression Matching</li>
    <p>Given an input string (s) and a pattern (p), implement regular expression matching with support for '.' and '*'.</p>
    <pre><code>bool isMatch(string s, string p);</code></pre>
    <p>使用动态规划解决。</p>

    <li class="text-primary">Container With Most Water</li>
    <pre><code>int maxArea(vector&lt;int&gt;& height);</code></pre>
    <p>求容纳水的面积，最开始的两端算起。</p>

    <li class="text-success">Integer to Roman</li>
    <p>Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 to 3999.</p>
    <pre><code>string intToRoman(int num);</code></pre>
    <p>把所有的可能使用数组表示出来，直接用下标获取数组值。</p>

    <li class="text-secondary">Roman to Integer</li>
    <p>Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999.</p>
    <pre><code>int romanToInt(string s);</code></pre>
    <p>从后往前开始计算。</p>

    <li class="text-info">Longest Common Prefix</li>
    <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
    <pre><code>string longestCommonPrefix(vector&lt;string&gt;& strs);</code></pre>
    <p>两个for循环比较相同字符。</p>


    <li class="text-secondary">3Sum</li>
    <p>Given an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.</p>
    <pre><code>vector&lt;vector&lt;int&gt;&gt; threeSum(vector&lt;int&gt;& nums);</code></pre>
    <p>固定一个数，移动其它两个数，找到相等的位置。</p>

    <li class="text-info">3Sum Closest</li>
    <p>Given an array nums of n integers and an integer target, find three integers in nums such that the sum is closest to target. Return the sum of the three integers. You may assume that each input would have exactly one solution.</p>
    <pre><code>int threeSumClosest(vector&lt;int&gt;& nums, int target);</code></pre>
    <p>类似上面3Sum的例子。</p>

    <li class="text-primary">Letter Combinations of a Phone Number</li>
    <p>Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent.</p>
    <pre><code>vector&lt;string&gt; letterCombinations(string digits);</code></pre>
    <p>将字符串拆分。</p>

    <li class="text-warning">4Sum</li>
    <p>Given an array nums of n integers and an integer target, are there elements a, b, c, and d in nums such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.</p>
    <pre><code>vector&lt;vector&lt;int&gt;&gt; fourSum(vector&lt;int&gt;& nums, int target)</code></pre>
    <p>有点像分治法，从四个转化到三个，再转化到两个相加。</p>

    <li class="text-success">Remove Nth Node From End of List</li>
    <p>Given a linked list, remove the n-th node from the end of list and return its head.</p>
    <pre><code>ListNode* removeNthFromEnd(ListNode* head, int n);</code></pre>
    <p>使用两个指针，先before指针向前移动N个位置，然后before和after一起移动找到倒数第N个位置。</p>

    <li class="">Valid Parentheses</li>
    <p>Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.</p>
    <pre><code>bool isValid(string s);</code></pre>
    <p>堆栈的的执行速度不够快。</p>


    <li>Merge Two Sorted Lists</li>
    <p>Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.</p>
    <pre><code>ListNode* mergeTwoLists(ListNode* l1, ListNode* l2);</code></pre>
    <p>使用Recursive的方式更快。</p>

    <li>Generate Parentheses</li>
    <p></p>
    <p>使用迭代不断改变左右的括号个数。</p>

    <li>Merge k Sorted Lists</li>
    <p>不断地进行两个合并。</p>

    <li>Swap Nodes in Pairs</li>
    <p>使用迭代运行太慢。</p>

    <li>Reverse Nodes in k-Group</li>
    <p>current在交换时一直都没有变，申明pre_header是因为首地址会发生变化。</p>

    <li>Remove Duplicates from Sorted Array</li>
    <p>Given a sorted array nums, remove the duplicates in-place such that each element appear only once and return the new length.</p>
    <pre><code>int removeDuplicates(vector&lt;int&gt;& nums);</code></pre>
    <p>使用count计算重复的数组。</p>

    <li></li>
    <p></p>
    <pre><code>int removeElement(vector&lt;int&gt;& nums, int val);</code></pre>
    <p>移除指定元素之间的所有值。</p>

    <li>Implement strStr()</li>
    <p>Return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.</p>
    <pre><code>int strStr(string haystack, string needle);</code></pre>
    <p>brute-force暴力攻击法，也可以使用KMP算法进行查找。</p>

    <li>Divide Two Integers</li>
    <p>Given two integers dividend (被除数) and divisor (除数), divide two integers without using multiplication, division and mod operator.</p>
    <pre><code>int divide(int dividend, int divisor);</code></pre>
    <p>使用减法操作。</p>

    <li class="text-danger">Substring with Concatenation of All Words</li>



    <li>0053 Maximum Subarray</li>
    <p>Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.</p>
    <pre><code>int maxSubArray(vector&lt;int&gt;& nums);</code></pre>
    <p>使用divide and conquer方式。</p>
</ol>


<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
</body>
</html>